<?php

namespace app\admin\model;

use think\Model;
use app\admin\model\User;

class Order extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'order_stutas_text'
    ];
    

    
    public function getOrderStutasList()
    {
        return ['1' => __('Order_stutas 1'), '2' => __('Order_stutas 2'), '3是' => __('Order_stutas 3是'), '4' => __('Order_stutas 4')];
    }


    public function getOrderStutasTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_stutas']) ? $data['order_stutas'] : '');
        $list = $this->getOrderStutasList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function address()
    {
        return $this->belongsTo('Address', 'address_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function orderchild()
    {
        return $this->belongsTo('OrderChild', 'id', 'order_id', [], 'LEFT')->setEagerlyType(0);
    }
}
